home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-4.0 / bfd / aoutx.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-24  |  50.2 KB  |  1,679 lines

  1. /* BFD semi-generic back-end for a.out binaries
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*doc*
  22. @section a.out backends
  23.  
  24. BFD supports a number of different flavours of a.out format, though
  25. the major differences are only the sizes of the structures on disk,
  26. and the shape of the relocation information. 
  27.  
  28. The support is split into a basic support file @code{aoutx.h} and
  29. other files which derive functions from the base. One derivation file
  30. is @code{aoutf1.h} (for a.out flavour 1), and adds to the basic a.out
  31. functions support for sun3, sun4, 386 and 29k a.out files, to create a
  32. target jump vector for a specific target.
  33.  
  34. This information is further split out into more specific files for each
  35. machine, including @code{sunos.c} - for sun3 and sun4 and
  36. @code{demo64} for a demonstration of a 64 bit a.out format.
  37.  
  38. The base file @code{aoutx.h} defines general mechanisms for reading
  39. and writing records to and from disk, and various other methods which
  40. BFD requires. It is included by @code{aout32.c} and @code{aout64.c} to
  41. form the names aout_32_swap_exec_header_in,
  42. aout_64_swap_exec_header_in, etc.
  43.  
  44. As an example, this is what goes on to make the back end for a sun4, from aout32.c
  45.  
  46. @example
  47.    #define ARCH_SIZE 32
  48.    #include "aoutx.h"
  49. @end example
  50.  
  51. Which exports names:
  52. @example
  53.     ...
  54.    aout_32_canonicalize_reloc
  55.    aout_32_find_nearest_line
  56.    aout_32_get_lineno
  57.    aout_32_get_reloc_upper_bound
  58.      ...
  59. @end example
  60.  
  61. from sunos.c
  62.  
  63. @example   
  64.     #define ARCH 32
  65.     #define TARGET_NAME "a.out-sunos-big"
  66.     #define VECNAME    sunos_big_vec
  67.     #include "aoutf1.h"
  68. @end example
  69. requires all the names from aout32.c, and produces the jump vector
  70.  
  71. @example
  72.     sunos_big_vec
  73. @end example
  74.  
  75. The file host-aout.c is a special case.  It is for a large set of hosts
  76. that use ``more or less standard'' a.out files, and for which cross-debugging
  77. is not interesting.  It uses the standard 32-bit a.out support routines,
  78. but determines the file offsets and addresses of the text, data,
  79. and BSS sections, the machine architecture and machine type,
  80. and the entry point address, in a host-dependent manner.  Once these
  81. values have been determined, generic code is used to handle the 
  82. object file.
  83.  
  84. When porting it to run on a new system, you must supply:
  85.  
  86.         HOST_PAGE_SIZE
  87.         HOST_SEGMENT_SIZE
  88.         HOST_MACHINE_ARCH       (optional)
  89.         HOST_MACHINE_MACHINE    (optional)
  90.         HOST_TEXT_START_ADDR
  91.         HOST_STACK_END_ADDR
  92.  
  93. in the file ../include/sys/h-XXX.h (for your host).  These values, plus
  94. the structures and macros defined in <a.out.h> on your host system, will
  95. produce a BFD target that will access ordinary a.out files on your host.
  96.  
  97. To configure a new machine to use host-aout.c, specify:
  98.  
  99. TDEFINES = -DDEFAULT_VECTOR=host_aout_big_vec
  100. TDEPFILES= host-aout.o trad-core.o
  101.  
  102. in the config/tmake-XXX file, and modify configure.in to use the
  103. tmake-XXX file (by setting "bfd_target=XXX") when your configuration is
  104. selected.
  105.  
  106. */
  107.  
  108. #define KEEPIT flags
  109. #define KEEPITTYPE int
  110.  
  111. #include "bfd.h"
  112. #include <sysdep.h>
  113. #include <ansidecl.h>
  114.  
  115. struct external_exec;
  116. #include "libaout.h"
  117. #include "libbfd.h"
  118. #include "aout64.h"
  119. #include "stab.gnu.h"
  120. #include "ar.h"
  121.  
  122. void (*bfd_error_trap)();
  123.  
  124. /*doc*
  125. @subsection relocations
  126. The file @code{aoutx.h} caters for both the @emph{standard} and
  127. @emph{extended} forms of a.out relocation records.
  128.  
  129. The standard records are characterised by containing only an address,
  130. a symbol index and a type field. The extended records (used on 29ks
  131. and sparcs) also have a full integer for an addend. 
  132. */
  133. #define CTOR_TABLE_RELOC_IDX 2
  134.  
  135.  
  136. static  reloc_howto_type howto_table_ext[] = 
  137. {
  138.   HOWTO(RELOC_8,      0,  0,      8,  false, 0, true,  true,0,"8",      false, 0,0x000000ff, false),
  139.   HOWTO(RELOC_16,     0,  1,     16, false, 0, true,  true,0,"16",      false, 0,0x0000ffff, false),
  140.   HOWTO(RELOC_32,     0,  2,     32, false, 0, true,  true,0,"32",      false, 0,0xffffffff, false),
  141.   HOWTO(RELOC_DISP8,  0,  0,     8,  true,  0, false, true,0,"DISP8",     false, 0,0x000000ff, false),
  142.   HOWTO(RELOC_DISP16, 0,  1,     16, true,  0, false, true,0,"DISP16",     false, 0,0x0000ffff, false),
  143.   HOWTO(RELOC_DISP32, 0,  2,     32, true,  0, false, true,0,"DISP32",     false, 0,0xffffffff, false),
  144.   HOWTO(RELOC_WDISP30,2,  2,     30, true,  0, false, true,0,"WDISP30",     false, 0,0x3fffffff, false),
  145.   HOWTO(RELOC_WDISP22,2,  2,     22, true,  0, false, true,0,"WDISP22",     false, 0,0x003fffff, false),
  146.   HOWTO(RELOC_HI22,   10, 2,     22, false, 0, false, true,0,"HI22",    false, 0,0x003fffff, false),
  147.   HOWTO(RELOC_22,      0, 2,     22, false, 0, false, true,0,"22",       false, 0,0x003fffff, false),
  148.   HOWTO(RELOC_13,     0, 2,     13, false, 0, false, true,0,"13",       false, 0,0x00001fff, false),
  149.   HOWTO(RELOC_LO10,     0, 2,     10, false, 0, false, true,0,"LO10",     false, 0,0x000003ff, false),
  150.   HOWTO(RELOC_SFA_BASE,0, 2,     32, false, 0, false, true,0,"SFA_BASE", false, 0,0xffffffff, false),
  151.   HOWTO(RELOC_SFA_OFF13,0,2,     32, false, 0, false, true,0,"SFA_OFF13",false, 0,0xffffffff, false),
  152.   HOWTO(RELOC_BASE10, 0,  2,     16, false, 0, false, true,0,"BASE10",   false, 0,0x0000ffff, false),
  153.   HOWTO(RELOC_BASE13, 0,  2,    13, false, 0, false, true,0,"BASE13",   false, 0,0x00001fff, false),
  154.   HOWTO(RELOC_BASE22, 0,  2,    0,  false, 0, false, true,0,"BASE22",   false, 0,0x00000000, false),
  155.   HOWTO(RELOC_PC10,   0,  2,    10, false, 0, false, true,0,"PC10",    false, 0,0x000003ff, false),
  156.   HOWTO(RELOC_PC22,   0,  2,    22, false, 0, false, true,0,"PC22",    false, 0,0x003fffff, false),
  157.   HOWTO(RELOC_JMP_TBL,0,  2,    32, false, 0, false, true,0,"JMP_TBL",    false, 0,0xffffffff, false),
  158.   HOWTO(RELOC_SEGOFF16,0, 2,    0,  false, 0, false, true,0,"SEGOFF16",    false, 0,0x00000000, false),
  159.   HOWTO(RELOC_GLOB_DAT,0, 2,    0,  false, 0, false, true,0,"GLOB_DAT",    false, 0,0x00000000, false),
  160.   HOWTO(RELOC_JMP_SLOT,0, 2,    0,  false, 0, false, true,0,"JMP_SLOT",    false, 0,0x00000000, false),
  161.   HOWTO(RELOC_RELATIVE,0, 2,    0,  false, 0, false,    true,0,"RELATIVE",    false, 0,0x00000000, false),
  162.  
  163. };
  164.  
  165. /* Convert standard reloc records to "arelent" format (incl byte swap).  */
  166.  
  167. static  reloc_howto_type howto_table_std[] = {
  168.   /* type           rs   size bsz  pcrel bitpos  abs ovrf sf name    part_inpl   readmask  setmask  pcdone */
  169. HOWTO( 0,           0,  0,      8,  false, 0, true,  true,0,"8",    true, 0x000000ff,0x000000ff, false),
  170. HOWTO( 1,           0,  1,     16, false, 0, true,  true,0,"16",    true, 0x0000ffff,0x0000ffff, false),
  171. HOWTO( 2,           0,  2,     32, false, 0, true,  true,0,"32",    true, 0xffffffff,0xffffffff, false),
  172. HOWTO( 3,           0,  3,     64, false, 0, true,  true,0,"64",       true, 0xdeaddead,0xdeaddead, false),
  173. HOWTO( 4,           0,  0,     8,  true,  0, false, true,0,"DISP8",    true, 0x000000ff,0x000000ff, false),
  174. HOWTO( 5,           0,  1,     16, true,  0, false, true,0,"DISP16",   true, 0x0000ffff,0x0000ffff, false),
  175. HOWTO( 6,           0,  2,     32, true,  0, false, true,0,"DISP32",   true, 0xffffffff,0xffffffff, false),
  176. HOWTO( 7,           0,  3,     64, true,  0, false, true,0,"DISP64",   true, 0xfeedface,0xfeedface, false),
  177. };
  178.  
  179.  
  180. bfd_error_vector_type bfd_error_vector;
  181.  
  182. /*doc*
  183. @subsection Internal Entry Points
  184. @code{aoutx.h} exports several routines for accessing the contents of
  185. an a.out file, which are gathered and exported in turn by various
  186. format specific files (eg sunos.c).
  187. */
  188.  
  189. /*doc*
  190. *i aout_<size>_swap_exec_header_in
  191. Swaps the information in an executable header taken from a raw byte stream memory image,
  192. into the internal exec_header structure.
  193. *; PROTO(void, aout_<size>_swap_exec_header_in,
  194.       (bfd *abfd,
  195.       struct external_exec *raw_bytes,
  196.       struct internal_exec *execp));
  197. */
  198.      
  199. void
  200. DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp),
  201.       bfd *abfd AND
  202.       struct external_exec *raw_bytes AND
  203.       struct internal_exec *execp)
  204. {
  205.   struct external_exec *bytes = (struct external_exec *)raw_bytes;
  206.  
  207.   /* Now fill in fields in the execp, from the bytes in the raw data.  */
  208.   execp->a_info   = bfd_h_get_32 (abfd, bytes->e_info);
  209.   execp->a_text   = GET_WORD (abfd, bytes->e_text);
  210.   execp->a_data   = GET_WORD (abfd, bytes->e_data);
  211.   execp->a_bss    = GET_WORD (abfd, bytes->e_bss);
  212.   execp->a_syms   = GET_WORD (abfd, bytes->e_syms);
  213.   execp->a_entry  = GET_WORD (abfd, bytes->e_entry);
  214.   execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
  215.   execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
  216. }
  217.  
  218. /*doc*
  219. *i aout_<size>_swap_exec_header_out
  220. Swaps the information in an internal exec header structure into the
  221. supplied buffer ready for writing to disk.
  222. *; PROTO(void, aout_<size>_swap_exec_header_out,
  223.       (bfd *abfd,
  224.        struct internal_exec *execp,
  225.        struct external_exec *raw_bytes));
  226. */
  227. void
  228. DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes),
  229.      bfd *abfd AND
  230.      struct internal_exec *execp AND 
  231.      struct external_exec *raw_bytes)
  232. {
  233.   struct external_exec *bytes = (struct external_exec *)raw_bytes;
  234.  
  235.   /* Now fill in fields in the raw data, from the fields in the exec struct. */
  236.   bfd_h_put_32 (abfd, execp->a_info  , bytes->e_info);
  237.   PUT_WORD (abfd, execp->a_text  , bytes->e_text);
  238.   PUT_WORD (abfd, execp->a_data  , bytes->e_data);
  239.   PUT_WORD (abfd, execp->a_bss   , bytes->e_bss);
  240.   PUT_WORD (abfd, execp->a_syms  , bytes->e_syms);
  241.   PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
  242.   PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
  243.   PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
  244. }
  245.  
  246. struct container {
  247.     struct aoutdata a;
  248.     struct internal_exec e;
  249. };
  250.  
  251.  
  252. /*doc*
  253. *i aout_<size>_some_aout_object_p
  254.  
  255. Some A.OUT variant thinks that the file whose format we're checking
  256. is an a.out file.  Do some more checking, and set up for access if
  257. it really is.  Call back to the calling environments "finish up"
  258. function just before returning, to handle any last-minute setup.  
  259.  
  260. *; PROTO(bfd_target *, aout_<size>_some_aout_object_p,
  261.      (bfd *abfd,
  262.       bfd_target *(*callback_to_real_object_p)()));
  263. */
  264.  
  265. bfd_target *
  266. DEFUN(NAME(aout,some_aout_object_p),(abfd, callback_to_real_object_p),
  267.       bfd *abfd AND
  268.       bfd_target *(*callback_to_real_object_p) ())
  269. {
  270.   struct external_exec exec_bytes;
  271.   struct internal_exec *execp;
  272.   struct container *rawptr;
  273.  
  274.   if (bfd_seek (abfd, 0L, false) < 0) {
  275.     bfd_error = system_call_error;
  276.     return 0;
  277.   }
  278.  
  279.   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
  280.       != EXEC_BYTES_SIZE) {
  281.     bfd_error = wrong_format;
  282.     return 0;
  283.   }
  284.  
  285.   /* Use an intermediate variable for clarity */
  286.   rawptr = (struct container *) bfd_zalloc (abfd, sizeof (struct container));
  287.  
  288.   if (rawptr == NULL) {
  289.     bfd_error = no_memory;
  290.     return 0;
  291.   }
  292.  
  293.   set_tdata (abfd, rawptr);
  294.   exec_hdr (abfd) = execp = &(rawptr->e);
  295.   NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, execp);
  296.  
  297.   /* Set the file flags */
  298.   abfd->flags = NO_FLAGS;
  299.   if (execp->a_drsize || execp->a_trsize)
  300.     abfd->flags |= HAS_RELOC;
  301.   if (execp->a_entry) 
  302.     abfd->flags |= EXEC_P;
  303.   if (execp->a_syms) 
  304.     abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
  305.  
  306.   if (N_MAGIC (*execp) == ZMAGIC) abfd->flags |= D_PAGED;
  307.   if (N_MAGIC (*execp) == NMAGIC) abfd->flags |= WP_TEXT;
  308.  
  309.   bfd_get_start_address (abfd) = execp->a_entry;
  310.  
  311.   obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
  312.   bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
  313.  
  314.   /* Set the default architecture and machine type.  These can be
  315.      overridden in the callback routine.  */
  316.   abfd->obj_arch = bfd_arch_unknown;
  317.   abfd->obj_machine = 0;
  318.  
  319.   /* The default relocation entry size is that of traditional V7 Unix.  */
  320.   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  321.  
  322.   /* create the sections.  This is raunchy, but bfd_close wants to reclaim
  323.      them */
  324.   obj_textsec (abfd) = (asection *)NULL;
  325.   obj_datasec (abfd) = (asection *)NULL;
  326.   obj_bsssec (abfd) = (asection *)NULL;
  327.   (void)bfd_make_section(abfd, ".text");
  328.   (void)bfd_make_section(abfd, ".data");
  329.   (void)bfd_make_section(abfd, ".bss");
  330.  
  331.   abfd->sections = obj_textsec (abfd);
  332.   obj_textsec (abfd)->next = obj_datasec (abfd);
  333.   obj_datasec (abfd)->next = obj_bsssec (abfd);
  334.  
  335.   obj_datasec (abfd)->size = execp->a_data;
  336.   obj_bsssec (abfd)->size = execp->a_bss;
  337.   obj_textsec (abfd)->size = execp->a_text;
  338.  
  339.   if (abfd->flags & D_PAGED) {
  340.     obj_textsec (abfd)->size -=  EXEC_BYTES_SIZE;
  341.   }
  342.     
  343.  
  344.   obj_textsec (abfd)->flags = (execp->a_trsize != 0 ?
  345.                                (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) :
  346.                                (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS));
  347.   obj_datasec (abfd)->flags = (execp->a_drsize != 0 ?
  348.                                (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) :
  349.                                (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS));
  350.   obj_bsssec (abfd)->flags = SEC_ALLOC;
  351.  
  352. #ifdef THIS_IS_ONLY_DOCUMENTATION
  353.   /* Call back to the format-dependent code to fill in the rest of the 
  354.      fields and do any further cleanup.  Things that should be filled
  355.      in by the callback:  */
  356.  
  357.   struct exec *execp = exec_hdr (abfd);
  358.  
  359.   /* The virtual memory addresses of the sections */
  360.   obj_datasec (abfd)->vma = N_DATADDR(*execp);
  361.   obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
  362.   obj_textsec (abfd)->vma = N_TXTADDR(*execp);
  363.  
  364.   /* The file offsets of the sections */
  365.   obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
  366.   obj_datasec (abfd)->filepos = N_DATOFF(*execp);
  367.  
  368.   /* The file offsets of the relocation info */
  369.   obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
  370.   obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
  371.  
  372.   /* The file offsets of the string table and symbol table.  */
  373.   obj_str_filepos (abfd) = N_STROFF (*execp);
  374.   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
  375.  
  376.   /* This common code can't fill in those things because they depend
  377.      on either the start address of the text segment, the rounding
  378.      up of virtual addersses between segments, or the starting file 
  379.      position of the text segment -- all of which varies among different
  380.      versions of a.out.  */
  381.  
  382.   /* Determine the architecture and machine type of the object file.  */
  383.   switch (N_MACHTYPE (*exec_hdr (abfd))) {
  384.   default:
  385.     abfd->obj_arch = bfd_arch_obscure;
  386.     break;
  387.   }
  388.  
  389.   /* Determine the size of a relocation entry */
  390.   switch (abfd->obj_arch) {
  391.   case bfd_arch_sparc:
  392.   case bfd_arch_a29k:
  393.     obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
  394.   default:
  395.     obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  396.   }
  397.  
  398.   return abfd->xvec;
  399.  
  400.   /* The architecture is encoded in various ways in various a.out variants,
  401.      or is not encoded at all in some of them.  The relocation size depends
  402.      on the architecture and the a.out variant.  Finally, the return value
  403.      is the bfd_target vector in use.  If an error occurs, return zero and
  404.      set bfd_error to the appropriate error code.
  405.      
  406.      Formats such as b.out, which have additional fields in the a.out
  407.      header, should cope with them in this callback as well.  */
  408. #endif                /* DOCUMENTATION */
  409.  
  410.  
  411.   return (*callback_to_real_object_p)(abfd);
  412. }
  413.  
  414. /*doc*
  415. *i aout_<size>_mkobject
  416.  
  417. This routine initializes a BFD for use with a.out files.
  418.  
  419. *; PROTO(boolean, aout_<size>_mkobject, (bfd *));
  420. */
  421.  
  422. boolean
  423. DEFUN(NAME(aout,mkobject),(abfd),
  424.      bfd *abfd)
  425. {
  426.   struct container *rawptr;
  427.  
  428.   bfd_error = system_call_error;
  429.  
  430.   /* Use an intermediate variable for clarity */
  431.   rawptr = (struct container *)bfd_zalloc (abfd, sizeof (struct container));
  432.   
  433.   if (rawptr == NULL) {
  434.     bfd_error = no_memory;
  435.     return false;
  436.   }
  437.   
  438.   set_tdata (abfd, rawptr);
  439.   exec_hdr (abfd) = &(rawptr->e);
  440.   
  441.   /* For simplicity's sake we just make all the sections right here. */
  442.   
  443.   obj_textsec (abfd) = (asection *)NULL;
  444.   obj_datasec (abfd) = (asection *)NULL;
  445.   obj_bsssec (abfd) = (asection *)NULL;
  446.   bfd_make_section (abfd, ".text");
  447.   bfd_make_section (abfd, ".data");
  448.   bfd_make_section (abfd, ".bss");
  449.   
  450.   return true;
  451. }
  452.  
  453.  
  454. /*doc*
  455. *i aout_<size>_machine_type
  456.  
  457. Keep track of machine architecture and machine type for a.out's.
  458. Return the machine_type for a particular arch&machine, or M_UNKNOWN
  459. if that exact arch&machine can't be represented in a.out format.
  460.  
  461. If the architecture is understood, machine type 0 (default) should
  462. always be understood.  
  463.  
  464. *; PROTO(enum machine_type, aout_<size>_machine_type,
  465.      (enum bfd_architecture arch,
  466.       unsigned long machine));
  467. */
  468.  
  469. enum machine_type
  470. DEFUN(NAME(aout,machine_type),(arch, machine),
  471.       enum bfd_architecture arch AND
  472.       unsigned long machine)
  473. {
  474.   enum machine_type arch_flags;
  475.     
  476.   arch_flags = M_UNKNOWN;
  477.     
  478.   switch (arch) {
  479.   case bfd_arch_sparc:
  480.     if (machine == 0)    arch_flags = M_SPARC;
  481.     break;
  482.       
  483.   case bfd_arch_m68k:
  484.     switch (machine) {
  485.     case 0:        arch_flags = M_68010; break;
  486.     case 68000:        arch_flags = M_UNKNOWN;    break;
  487.     case 68010:        arch_flags = M_68010; break;
  488.     case 68020:        arch_flags = M_68020; break;
  489.     default:        arch_flags = M_UNKNOWN; break;
  490.     }
  491.     break;
  492.       
  493.   case bfd_arch_i386:
  494.     if (machine == 0)    arch_flags = M_386;
  495.     break;
  496.       
  497.   case bfd_arch_a29k:
  498.     if (machine == 0)    arch_flags = M_29K;
  499.     break;
  500.       
  501.   default:
  502.     arch_flags = M_UNKNOWN;
  503.     break;
  504.   }
  505.   return arch_flags;
  506. }
  507.  
  508. /*doc*
  509. *i aout_<size>_set_arch_mach
  510.  
  511. Sets the architecture and the machine of the BFD to those values
  512. supplied. Verifies that the format can support the architecture
  513. required.
  514.  
  515. *; PROTO(boolean, aout_<size>_set_arch_mach,
  516.      (bfd *,
  517.       enum bfd_architecture,
  518.       unsigned long machine));
  519. */
  520.  
  521. boolean
  522. DEFUN(NAME(aout,set_arch_mach),(abfd, arch, machine),
  523.       bfd *abfd AND
  524.       enum bfd_architecture arch AND
  525.       unsigned long machine)
  526. {
  527.   abfd->obj_arch = arch;
  528.   abfd->obj_machine = machine;
  529.   if (arch != bfd_arch_unknown &&
  530.       NAME(aout,machine_type) (arch, machine) == M_UNKNOWN)
  531.     return false;        /* We can't represent this type */
  532.   return true;            /* We're easy ... */
  533. }
  534.  
  535. /*doc*
  536. *i aout_<size>new_section_hook
  537.  
  538. Called by the BFD in response to a @code{bfd_make_section} request.
  539. *; PROTO(boolean, aout_<size>_new_section_hook,
  540.          (bfd *abfd,
  541.       asection *newsect));
  542. */
  543. boolean
  544. DEFUN(NAME(aout,new_section_hook),(abfd, newsect),
  545.       bfd *abfd AND
  546.       asection *newsect)
  547. {
  548.   /* align to double at least */
  549.   newsect->alignment_power = 3;
  550.     
  551.   if (bfd_get_format (abfd) == bfd_object) {
  552.     if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
  553.       obj_textsec(abfd)= newsect;
  554.       return true;
  555.     }
  556.       
  557.     if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {
  558.       obj_datasec(abfd) = newsect;
  559.       return true;
  560.     }
  561.       
  562.     if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {
  563.       obj_bsssec(abfd) = newsect;
  564.       return true;
  565.     }
  566.   }
  567.     
  568.   /* We allow more than three sections internally */
  569.   return true;
  570. }
  571.  
  572. boolean
  573. DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),
  574.       bfd *abfd AND
  575.       sec_ptr section AND
  576.       PTR location AND
  577.       file_ptr offset AND
  578.       bfd_size_type count)
  579. {
  580.   if (abfd->output_has_begun == false)
  581.       {                /* set by bfd.c handler */
  582.     if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL)) 
  583.         {
  584.           bfd_error = invalid_operation;
  585.           return false;
  586.         }
  587. /*    if (abfd->flags & D_PAGED) {      
  588.       obj_textsec(abfd)->filepos = 0;
  589.     }
  590.     else*/ {
  591.       obj_textsec(abfd)->filepos = EXEC_BYTES_SIZE;
  592.     }
  593.     obj_textsec(abfd)->size = align_power(obj_textsec(abfd)->size,
  594.                           obj_textsec(abfd)->alignment_power);
  595.     obj_datasec(abfd)->filepos =  obj_textsec (abfd)->size + EXEC_BYTES_SIZE;
  596.     obj_datasec(abfd)->size = align_power(obj_datasec(abfd)->size,
  597.                           obj_datasec(abfd)->alignment_power);
  598.       
  599.       
  600.       }
  601.   /* regardless, once we know what we're doing, we might as well get going */
  602.   if (section != obj_bsssec(abfd)) 
  603.       {
  604.     bfd_seek (abfd, section->filepos + offset, SEEK_SET);
  605.       
  606.     if (count) {
  607.       return (bfd_write ((PTR)location, 1, count, abfd) == count) ?
  608.         true : false;
  609.     }
  610.     return false;
  611.       }
  612.   return true;
  613. }
  614.  
  615. /* Classify stabs symbols */
  616.  
  617. #define sym_in_text_section(sym) \
  618. (((sym)->type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
  619.  
  620. #define sym_in_data_section(sym) \
  621. (((sym)->type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
  622.  
  623. #define sym_in_bss_section(sym) \
  624. (((sym)->type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
  625.  
  626. /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
  627. zero in the "value" field.  Nonzeroes there are fortrancommon
  628. symbols.  */
  629. #define sym_is_undefined(sym) \
  630. ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0)
  631.  
  632. /* Symbol is a global definition if N_EXT is on and if it has
  633. a nonzero type field.  */
  634. #define sym_is_global_defn(sym) \
  635. (((sym)->type & N_EXT) && (sym)->type & N_TYPE)
  636.  
  637. /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
  638. are on.  */
  639. #define sym_is_debugger_info(sym) \
  640. ((sym)->type & ~(N_EXT | N_TYPE))
  641.  
  642. #define sym_is_fortrancommon(sym)       \
  643. (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)
  644.  
  645. /* Symbol is absolute if it has N_ABS set */
  646. #define sym_is_absolute(sym) \
  647. (((sym)->type  & N_TYPE)== N_ABS)
  648.  
  649.  
  650. #define sym_is_indirect(sym) \
  651. (((sym)->type & N_ABS)== N_ABS)
  652.  
  653. /* Only in their own functions for ease of debugging; when sym flags have
  654. stabilised these should be inlined into their (single) caller */
  655.  
  656. static void
  657. DEFUN(translate_from_native_sym_flags,(sym_pointer, cache_ptr, abfd),
  658.       struct external_nlist *sym_pointer AND
  659.       aout_symbol_type *cache_ptr AND
  660.       bfd *abfd)
  661.   {
  662.     switch (cache_ptr->type & N_TYPE) {
  663.     case N_SETA:
  664.     case N_SETT:
  665.     case N_SETD:
  666.     case N_SETB:
  667.     {
  668.       char *copy = bfd_alloc(abfd, strlen(cache_ptr->symbol.name)+1);
  669.       asection *section ;
  670.       arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd, sizeof(arelent_chain));
  671.       strcpy(copy, cache_ptr->symbol.name);
  672.       section = bfd_make_section(abfd,copy);
  673.       switch ( (cache_ptr->type  & N_TYPE) ) {
  674.       case N_SETA:
  675.         section->flags = SEC_CONSTRUCTOR;
  676.         reloc->relent.section =  (asection *)NULL;
  677.         cache_ptr->symbol.section = (asection *)NULL;
  678.         break;
  679.       case N_SETT:
  680.         section->flags = SEC_CONSTRUCTOR_TEXT;
  681.         reloc->relent.section = (asection *)obj_textsec(abfd);
  682.         cache_ptr->symbol.value -= reloc->relent.section->vma;
  683.         break;
  684.       case N_SETD:
  685.         section->flags = SEC_CONSTRUCTOR_DATA;
  686.         reloc->relent.section = (asection *)obj_datasec(abfd);
  687.         cache_ptr->symbol.value -= reloc->relent.section->vma;
  688.         break;
  689.       case N_SETB:
  690.         section->flags = SEC_CONSTRUCTOR_BSS;
  691.         reloc->relent.section = (asection *)obj_bsssec(abfd);
  692.         cache_ptr->symbol.value -= reloc->relent.section->vma;
  693.         break;
  694.       }
  695.       cache_ptr->symbol.section = reloc->relent.section;
  696.       reloc->relent.addend = cache_ptr->symbol.value ;
  697.       
  698.       /* We modify the symbol to belong to a section depending upon the
  699.         name of the symbol - probably __CTOR__ or __DTOR__ but we don't
  700.           really care, and add to the size of the section to contain a
  701.         pointer to the symbol. Build a reloc entry to relocate to this
  702.           symbol attached to this section.  */
  703.       
  704.       
  705.       section->reloc_count++;
  706.       section->alignment_power = 2;
  707.       reloc->relent.sym_ptr_ptr = (asymbol **)NULL;
  708.       reloc->next = section->constructor_chain;
  709.       section->constructor_chain = reloc;
  710.       reloc->relent.address = section->size;
  711.       section->size += sizeof(int *);
  712.       
  713.       reloc->relent.howto = howto_table_ext +CTOR_TABLE_RELOC_IDX;
  714.       cache_ptr->symbol.flags |=  BSF_DEBUGGING  | BSF_CONSTRUCTOR;
  715.     }
  716.     break;
  717.   default:
  718.     if (cache_ptr->type ==  N_WARNING) 
  719.     {
  720.       /* This symbol is the text of a warning message, the next symbol
  721.      is the symbol to associate the warning with */
  722.       cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
  723.       cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1));
  724.       /* We furgle with the next symbol in place. We don't want it to be undefined, we'll trample the type */
  725.       (sym_pointer+1)->e_type[0] = 0xff;
  726.       break;
  727.     }
  728.     if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT)) {
  729.       /* Two symbols in a row for an INDR message. The first symbol
  730.      contains the name we will match, the second symbol contains the
  731.      name the first name is translated into. It is supplied to us
  732.      undefined. This is good, since we want to pull in any files which
  733.      define it */
  734.       cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT;
  735.       cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1));
  736.       break;
  737.     }
  738.  
  739.       
  740.     if (sym_is_debugger_info (cache_ptr)) {
  741.       cache_ptr->symbol.flags = BSF_DEBUGGING ;
  742.       /* Work out the section correct for this symbol */
  743.       switch (cache_ptr->type & N_TYPE) 
  744.       {
  745.       case N_TEXT:
  746.       case N_FN:
  747.         cache_ptr->symbol.section = obj_textsec (abfd);
  748.         cache_ptr->symbol.value -= obj_textsec(abfd)->vma;
  749.         break;
  750.       case N_DATA:
  751.         cache_ptr->symbol.value  -= obj_datasec(abfd)->vma;
  752.         cache_ptr->symbol.section = obj_datasec (abfd);
  753.         break;
  754.       case N_BSS :
  755.         cache_ptr->symbol.section = obj_bsssec (abfd);
  756.         cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;
  757.         break;
  758.       case N_ABS:
  759.       default:
  760.         cache_ptr->symbol.section = 0;
  761.         break;
  762.       }
  763.     }
  764.     else {
  765.  
  766.       if (sym_is_fortrancommon (cache_ptr))
  767.       {
  768.         cache_ptr->symbol.flags = BSF_FORT_COMM;
  769.         cache_ptr->symbol.section = (asection *)NULL;
  770.       }
  771.       else {
  772.     if (sym_is_undefined (cache_ptr)) {
  773.       cache_ptr->symbol.flags = BSF_UNDEFINED;
  774.     }
  775.     else if (sym_is_global_defn (cache_ptr)) {
  776.       cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
  777.     }
  778.       
  779.     else if (sym_is_absolute (cache_ptr)) {
  780.       cache_ptr->symbol.flags = BSF_ABSOLUTE;
  781.     }
  782.     else {
  783.       cache_ptr->symbol.flags = BSF_LOCAL;
  784.     }
  785.       
  786.     /* In a.out, the value of a symbol is always relative to the 
  787.      * start of the file, if this is a data symbol we'll subtract
  788.      * the size of the text section to get the section relative
  789.      * value. If this is a bss symbol (which would be strange)
  790.      * we'll subtract the size of the previous two sections
  791.      * to find the section relative address.
  792.      */
  793.       
  794.     if (sym_in_text_section (cache_ptr))   {
  795.       cache_ptr->symbol.value -= obj_textsec(abfd)->vma;
  796.       cache_ptr->symbol.section = obj_textsec (abfd);
  797.     }
  798.     else if (sym_in_data_section (cache_ptr)){
  799.       cache_ptr->symbol.value -= obj_datasec(abfd)->vma;
  800.       cache_ptr->symbol.section = obj_datasec (abfd);
  801.     }
  802.     else if (sym_in_bss_section(cache_ptr)) {
  803.       cache_ptr->symbol.section = obj_bsssec (abfd);
  804.       cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;
  805.     }
  806.     else {
  807.       cache_ptr->symbol.section = (asection *)NULL;
  808.       cache_ptr->symbol.flags |= BSF_ABSOLUTE;
  809.     }
  810.       }
  811.     }
  812.   }
  813. }
  814.  
  815. static void
  816. DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd),
  817.      struct external_nlist *sym_pointer AND
  818.      asymbol *cache_ptr AND
  819.      bfd *abfd)
  820. {
  821.   bfd_vma value = cache_ptr->value;
  822.  
  823.   if (bfd_get_section(cache_ptr)) {
  824.     if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
  825.       sym_pointer->e_type[0] |= N_BSS;
  826.     }
  827.     else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) {
  828.       sym_pointer->e_type[0] |= N_DATA;
  829.     }
  830.     else  if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) {
  831.       sym_pointer->e_type[0] |= N_TEXT;
  832.     }
  833.     else {
  834.       bfd_error_vector.nonrepresentable_section(abfd,
  835.                         bfd_get_output_section(cache_ptr)->name);
  836.     }
  837.     /* Turn the symbol from section relative to absolute again */
  838.     
  839.     value +=
  840.       cache_ptr->section->output_section->vma 
  841.     + cache_ptr->section->output_offset ;
  842.   }
  843.   else {
  844.     sym_pointer->e_type[0] |= N_ABS;
  845.   }
  846.   if (cache_ptr->flags & (BSF_WARNING)) {
  847.     (sym_pointer+1)->e_type[0] = 1;
  848.   }  
  849.   if (cache_ptr->flags & (BSF_FORT_COMM | BSF_UNDEFINED)) {
  850.     sym_pointer->e_type[0] = (N_UNDF | N_EXT);
  851.   }
  852.   else {
  853.     if (cache_ptr->flags & BSF_ABSOLUTE) {
  854.       sym_pointer->e_type[0] |= N_ABS;
  855.     }
  856.     
  857.     if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) {
  858.       sym_pointer->e_type[0] |= N_EXT;
  859.     }
  860.     if (cache_ptr->flags & BSF_DEBUGGING) {
  861.       sym_pointer->e_type [0]= ((aout_symbol_type *)cache_ptr)->type;
  862.     }
  863.   }
  864.   PUT_WORD(abfd, value, sym_pointer->e_value);
  865. }
  866.  
  867. /* Native-level interface to symbols. */
  868.  
  869. /* We read the symbols into a buffer, which is discarded when this
  870. function exits.  We read the strings into a buffer large enough to
  871. hold them all plus all the cached symbol entries. */
  872.  
  873. asymbol *
  874. DEFUN(NAME(aout,make_empty_symbol),(abfd),
  875.       bfd *abfd)
  876.   {
  877.     aout_symbol_type  *new =
  878.       (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
  879.     new->symbol.the_bfd = abfd;
  880.     
  881.     return &new->symbol;
  882.   }
  883.  
  884. boolean
  885. DEFUN(NAME(aout,slurp_symbol_table),(abfd),
  886.       bfd *abfd)
  887.   {
  888.     bfd_size_type symbol_size;
  889.     bfd_size_type string_size;
  890.     unsigned char string_chars[BYTES_IN_WORD];
  891.     struct external_nlist *syms;
  892.     char *strings;
  893.     aout_symbol_type *cached;
  894.     
  895.     /* If there's no work to be done, don't do any */
  896.     if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true;
  897.     symbol_size = exec_hdr(abfd)->a_syms;
  898.     if (symbol_size == 0) {
  899.       bfd_error = no_symbols;
  900.       return false;
  901.     }
  902.     
  903.     bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
  904.     if (bfd_read ((PTR)string_chars, BYTES_IN_WORD, 1, abfd) != BYTES_IN_WORD)
  905.       return false;
  906.     string_size = GET_WORD (abfd, string_chars);
  907.     
  908.     strings =(char *) bfd_alloc(abfd, string_size + 1);
  909.     cached = (aout_symbol_type *)
  910.       bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) * sizeof(aout_symbol_type)));
  911.  
  912.     /* malloc this, so we can free it if simply. The symbol caching
  913.        might want to allocate onto the bfd's obstack  */
  914.     syms = (struct external_nlist *) malloc(symbol_size);
  915.     bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
  916.     if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) {
  917.     bailout:
  918.       if (syms)     free (syms);
  919.       if (cached)    bfd_release (abfd, cached);
  920.       if (strings)bfd_release (abfd, strings);
  921.       return false;
  922.     }
  923.     
  924.     bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
  925.     if (bfd_read ((PTR)strings, 1, string_size, abfd) != string_size) {
  926.       goto bailout;
  927.     }
  928.     
  929.     /* OK, now walk the new symtable, cacheing symbol properties */
  930.       {
  931.     register struct external_nlist *sym_pointer;
  932.     register struct external_nlist *sym_end = syms + bfd_get_symcount (abfd);
  933.     register aout_symbol_type *cache_ptr = cached;
  934.     
  935.     /* Run through table and copy values */
  936.     for (sym_pointer = syms, cache_ptr = cached;
  937.          sym_pointer < sym_end; sym_pointer++, cache_ptr++) 
  938.         {
  939.           bfd_vma x = GET_WORD(abfd, sym_pointer->e_strx);
  940.           cache_ptr->symbol.the_bfd = abfd;
  941.           if (x)
  942.         cache_ptr->symbol.name = x + strings;
  943.           else
  944.         cache_ptr->symbol.name = (char *)NULL;
  945.           
  946.           cache_ptr->symbol.value = GET_SWORD(abfd,  sym_pointer->e_value);
  947.           cache_ptr->desc = bfd_get_16(abfd, sym_pointer->e_desc);
  948.           cache_ptr->other =bfd_get_8(abfd, sym_pointer->e_other);
  949.           cache_ptr->type = bfd_get_8(abfd,  sym_pointer->e_type);
  950.           cache_ptr->symbol.udata = 0;
  951.           translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd);
  952.         }
  953.       }
  954.     
  955.     obj_aout_symbols (abfd) =  cached;
  956.     free((PTR)syms);
  957.     
  958.     return true;
  959.   }
  960.  
  961.  
  962. void
  963. DEFUN(NAME(aout,write_syms),(abfd),
  964.       bfd *abfd)
  965.   {
  966.     unsigned int count ;
  967.     asymbol **generic = bfd_get_outsymbols (abfd);
  968.     
  969.     bfd_size_type stindex = BYTES_IN_WORD; /* initial string length */
  970.     
  971.     for (count = 0; count < bfd_get_symcount (abfd); count++) {
  972.       asymbol *g = generic[count];
  973.       struct external_nlist nsp;
  974.       
  975.       
  976.       if (g->name) {
  977.     unsigned int length = strlen(g->name) +1;
  978.     PUT_WORD  (abfd, stindex, (unsigned char *)nsp.e_strx);
  979.     stindex += length;
  980.       }
  981.       else {
  982.     PUT_WORD  (abfd, 0, (unsigned char *)nsp.e_strx);
  983.       }
  984.       
  985.       if (g->the_bfd->xvec->flavour == abfd->xvec->flavour) 
  986.       {
  987.         bfd_h_put_16(abfd, aout_symbol(g)->desc,  nsp.e_desc);
  988.         bfd_h_put_8(abfd, aout_symbol(g)->other,  nsp.e_other);
  989.         bfd_h_put_8(abfd, aout_symbol(g)->type,  nsp.e_type);
  990.       }
  991.       else
  992.       {
  993.         bfd_h_put_16(abfd,0, nsp.e_desc);
  994.         bfd_h_put_8(abfd, 0,  nsp.e_other);
  995.         bfd_h_put_8(abfd, 0,  nsp.e_type);
  996.       }
  997.       
  998.       
  999.       
  1000.       translate_to_native_sym_flags (&nsp, g, abfd);
  1001.       
  1002.       bfd_write((PTR)&nsp,1,EXTERNAL_LIST_SIZE, abfd);
  1003.     }
  1004.     
  1005.     
  1006.     /* Now output the strings.  Be sure to put string length into correct
  1007.       * byte ordering before writing it.
  1008.     */
  1009.       {
  1010.     char buffer[BYTES_IN_WORD];
  1011.     PUT_WORD  (abfd, stindex, (unsigned char *)buffer);
  1012.     
  1013.     bfd_write((PTR)buffer, 1, BYTES_IN_WORD, abfd);
  1014.       }
  1015.     generic = bfd_get_outsymbols(abfd);
  1016.     for (count = 0; count < bfd_get_symcount(abfd); count++) 
  1017.     {
  1018.       asymbol *g = *(generic++);
  1019.       
  1020.       if (g->name)
  1021.           {
  1022.         size_t length = strlen(g->name)+1;
  1023.         bfd_write((PTR)g->name, 1, length, abfd);
  1024.           }
  1025.       if ((g->flags & BSF_FAKE)==0) {
  1026.         g->KEEPIT = (KEEPITTYPE) count;
  1027.       }
  1028.     }
  1029.   }
  1030.  
  1031.  
  1032.  
  1033. unsigned int
  1034. DEFUN(NAME(aout,get_symtab),(abfd, location),
  1035.       bfd *abfd AND
  1036.       asymbol **location)
  1037.   {
  1038.     unsigned int counter = 0;
  1039.     aout_symbol_type *symbase;
  1040.     
  1041.     if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
  1042.     
  1043.     for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)
  1044.       *(location++) = (asymbol *)( symbase++);
  1045.     *location++ =0;
  1046.     return bfd_get_symcount(abfd);
  1047.   }
  1048.  
  1049.  
  1050. /* Standard reloc stuff */
  1051. /* Output standard relocation information to a file in target byte order. */
  1052.  
  1053. void
  1054. DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr),
  1055.       bfd *abfd AND
  1056.       arelent *g AND
  1057.       struct reloc_std_external *natptr)
  1058.   {
  1059.     int r_index;
  1060.     int r_extern;
  1061.     unsigned int r_length;
  1062.     int r_pcrel;
  1063.     int r_baserel, r_jmptable, r_relative;
  1064.     unsigned int r_addend;
  1065.     
  1066.     PUT_WORD(abfd, g->address, natptr->r_address);
  1067.     
  1068.     r_length = g->howto->size ; /* Size as a power of two */
  1069.     r_pcrel  = (int) g->howto->pc_relative; /* Relative to PC? */
  1070.     /* r_baserel, r_jmptable, r_relative???  FIXME-soon */
  1071.     r_baserel = 0;
  1072.     r_jmptable = 0;
  1073.     r_relative = 0;
  1074.     
  1075.     r_addend = g->addend;    /* Start here, see how it goes */
  1076.     
  1077.     /* name was clobbered by aout_write_syms to be symbol index */
  1078.     
  1079.     if (g->sym_ptr_ptr != NULL) 
  1080.     {
  1081.       if ((*(g->sym_ptr_ptr))->section) {
  1082.         /* put the section offset into the addend for output */
  1083.         r_addend += (*(g->sym_ptr_ptr))->section->vma;
  1084.       }
  1085.       
  1086.       r_index = ((*(g->sym_ptr_ptr))->KEEPIT);
  1087.       r_extern = 1;
  1088.     }
  1089.     else {
  1090.       r_extern = 0;
  1091.       if (g->section == NULL) {
  1092.     /* It is possible to have a reloc with nothing, we generate an
  1093.       abs + 0 */
  1094.     r_addend = 0;
  1095.     r_index = N_ABS | N_EXT;
  1096.       }
  1097.       else  if(g->section->output_section == obj_textsec(abfd)) {
  1098.     r_index = N_TEXT | N_EXT;
  1099.     r_addend += g->section->output_section->vma;
  1100.       }
  1101.       else if (g->section->output_section == obj_datasec(abfd)) {
  1102.     r_index = N_DATA | N_EXT;
  1103.     r_addend += g->section->output_section->vma;
  1104.       }
  1105.       else if (g->section->output_section == obj_bsssec(abfd)) {
  1106.     r_index = N_BSS | N_EXT ;
  1107.     r_addend += g->section->output_section->vma;
  1108.       }
  1109.       else {
  1110.     BFD_ASSERT(0);
  1111.       }
  1112.     }
  1113.     
  1114.     /* now the fun stuff */
  1115.     if (abfd->xvec->header_byteorder_big_p != false) {
  1116.       natptr->r_index[0] = r_index >> 16;
  1117.       natptr->r_index[1] = r_index >> 8;
  1118.       natptr->r_index[2] = r_index;
  1119.       natptr->r_type[0] =
  1120.     (r_extern?    RELOC_STD_BITS_EXTERN_BIG: 0)
  1121.       | (r_pcrel?     RELOC_STD_BITS_PCREL_BIG: 0)
  1122.         | (r_baserel?   RELOC_STD_BITS_BASEREL_BIG: 0)
  1123.           | (r_jmptable?  RELOC_STD_BITS_JMPTABLE_BIG: 0)
  1124.         | (r_relative?  RELOC_STD_BITS_RELATIVE_BIG: 0)
  1125.           | (r_length <<  RELOC_STD_BITS_LENGTH_SH_BIG);
  1126.     } else {
  1127.       natptr->r_index[2] = r_index >> 16;
  1128.       natptr->r_index[1] = r_index >> 8;
  1129.       natptr->r_index[0] = r_index;
  1130.       natptr->r_type[0] =
  1131.     (r_extern?    RELOC_STD_BITS_EXTERN_LITTLE: 0)
  1132.       | (r_pcrel?     RELOC_STD_BITS_PCREL_LITTLE: 0)
  1133.         | (r_baserel?   RELOC_STD_BITS_BASEREL_LITTLE: 0)
  1134.           | (r_jmptable?  RELOC_STD_BITS_JMPTABLE_LITTLE: 0)
  1135.         | (r_relative?  RELOC_STD_BITS_RELATIVE_LITTLE: 0)
  1136.           | (r_length <<  RELOC_STD_BITS_LENGTH_SH_LITTLE);
  1137.     }
  1138.   }
  1139.  
  1140.  
  1141. /* Extended stuff */
  1142. /* Output extended relocation information to a file in target byte order. */
  1143.  
  1144. void
  1145. DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),
  1146.       bfd *abfd AND
  1147.       arelent *g AND
  1148.       register struct reloc_ext_external *natptr)
  1149.   {
  1150.     int r_index;
  1151.     int r_extern;
  1152.     unsigned int r_type;
  1153.     unsigned int r_addend;
  1154.     
  1155.     PUT_WORD (abfd, g->address, natptr->r_address);
  1156.     
  1157.     /* Find a type in the output format which matches the input howto - 
  1158.       at the moment we assume input format == output format FIXME!! */
  1159.     r_type = (enum reloc_type) g->howto->type;
  1160.     
  1161.     r_addend = g->addend;    /* Start here, see how it goes */
  1162.  
  1163.   /* name was clobbered by aout_write_syms to be symbol index*/
  1164.  
  1165.   if (g->sym_ptr_ptr != NULL) 
  1166.     {
  1167.       if ((*(g->sym_ptr_ptr))->section) {
  1168.     /* put the section offset into the addend for output */
  1169.     r_addend += (*(g->sym_ptr_ptr))->section->vma;
  1170.       }
  1171.  
  1172.       r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT);
  1173.       r_extern = 1;
  1174.     }
  1175.   else {
  1176.     r_extern = 0;
  1177.     if (g->section == NULL) {
  1178.       BFD_ASSERT(0);
  1179.       r_index = N_ABS | N_EXT;
  1180.     }
  1181.     else  if(g->section->output_section == obj_textsec(abfd)) {
  1182.       r_index = N_TEXT | N_EXT;
  1183.       r_addend += g->section->output_section->vma;
  1184.     }
  1185.     else if (g->section->output_section == obj_datasec(abfd)) {
  1186.       r_index = N_DATA | N_EXT;
  1187.       r_addend += g->section->output_section->vma;
  1188.     }
  1189.     else if (g->section->output_section == obj_bsssec(abfd)) {
  1190.       r_index = N_BSS | N_EXT ;
  1191.       r_addend += g->section->output_section->vma;
  1192.     }
  1193.     else {
  1194.       BFD_ASSERT(0);
  1195.     }
  1196.   }
  1197.  
  1198.   /* now the fun stuff */
  1199.   if (abfd->xvec->header_byteorder_big_p != false) {
  1200.     natptr->r_index[0] = r_index >> 16;
  1201.     natptr->r_index[1] = r_index >> 8;
  1202.     natptr->r_index[2] = r_index;
  1203.     natptr->r_type[0] =
  1204.       (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0)
  1205.     | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG);
  1206.   } else {
  1207.     natptr->r_index[2] = r_index >> 16;
  1208.     natptr->r_index[1] = r_index >> 8;
  1209.     natptr->r_index[0] = r_index;
  1210.     natptr->r_type[0] =
  1211.       (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0)
  1212.     | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
  1213.   }
  1214.  
  1215.   PUT_WORD (abfd, r_addend, natptr->r_addend);
  1216. }
  1217.  
  1218. #define MOVE_ADDRESS(ad)                               \
  1219.   if (r_extern) {                            \
  1220.     cache_ptr->sym_ptr_ptr = symbols + r_index;                \
  1221.     cache_ptr->section = (asection *)NULL;                \
  1222.       cache_ptr->addend = ad;                        \
  1223.   } else {                                \
  1224.     cache_ptr->sym_ptr_ptr = (asymbol **)NULL;                \
  1225.     switch (r_index) {                            \
  1226.     case N_TEXT:                            \
  1227.     case N_TEXT | N_EXT:                        \
  1228.       cache_ptr->section = obj_textsec(abfd);                \
  1229.       cache_ptr->addend = ad  - su->textsec->vma;            \
  1230.       break;                                \
  1231.     case N_DATA:                            \
  1232.     case N_DATA | N_EXT:                        \
  1233.       cache_ptr->section = obj_datasec(abfd);                \
  1234.       cache_ptr->addend = ad - su->datasec->vma;            \
  1235.       break;                                \
  1236.     case N_BSS:                                \
  1237.     case N_BSS | N_EXT:                            \
  1238.       cache_ptr->section = obj_bsssec(abfd);                \
  1239.       cache_ptr->addend = ad - su->bsssec->vma;                \
  1240.       break;                                \
  1241.     case N_ABS:                                \
  1242.     case N_ABS | N_EXT:                            \
  1243.       cache_ptr->section = NULL;    /* No section */        \
  1244.       cache_ptr->addend = ad;        /* FIXME, is this right? */    \
  1245.       BFD_ASSERT(1);                            \
  1246.       break;                                \
  1247.     default:                                \
  1248.       cache_ptr->section = NULL;    /* No section */        \
  1249.       cache_ptr->addend = ad;        /* FIXME, is this right? */    \
  1250.       BFD_ASSERT(1);                            \
  1251.       break;                                \
  1252.     }                                    \
  1253.   }                                     \
  1254.  
  1255. void
  1256. DEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols),
  1257.       bfd *abfd AND
  1258.       struct reloc_ext_external *bytes AND
  1259.       arelent *cache_ptr AND
  1260.       asymbol **symbols)
  1261. {
  1262.   int r_index;
  1263.   int r_extern;
  1264.   unsigned int r_type;
  1265.   struct aoutdata *su = (struct aoutdata *)(abfd->tdata);
  1266.  
  1267.   cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
  1268.  
  1269.   /* now the fun stuff */
  1270.   if (abfd->xvec->header_byteorder_big_p != false) {
  1271.     r_index =  (bytes->r_index[0] << 16)
  1272.          | (bytes->r_index[1] << 8)
  1273.          |  bytes->r_index[2];
  1274.     r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
  1275.     r_type   =       (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
  1276.                       >> RELOC_EXT_BITS_TYPE_SH_BIG;
  1277.   } else {
  1278.     r_index =  (bytes->r_index[2] << 16)
  1279.          | (bytes->r_index[1] << 8)
  1280.          |  bytes->r_index[0];
  1281.     r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
  1282.     r_type   =       (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
  1283.                       >> RELOC_EXT_BITS_TYPE_SH_LITTLE;
  1284.   }
  1285.  
  1286.   cache_ptr->howto =  howto_table_ext + r_type;
  1287.   MOVE_ADDRESS(GET_SWORD(abfd,bytes->r_addend));
  1288. }
  1289.  
  1290. void
  1291. DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
  1292.   bfd *abfd AND
  1293.   struct reloc_std_external *bytes AND
  1294.   arelent *cache_ptr AND
  1295.   asymbol **symbols)
  1296. {
  1297.   int r_index;
  1298.   int r_extern;
  1299.   unsigned int r_length;
  1300.   int r_pcrel;
  1301.   int r_baserel, r_jmptable, r_relative;
  1302.   struct aoutdata *su = (struct aoutdata *)(abfd->tdata);
  1303.  
  1304.   cache_ptr->address = (int32_type)(bfd_h_get_32 (abfd, bytes->r_address));
  1305.  
  1306.   /* now the fun stuff */
  1307.   if (abfd->xvec->header_byteorder_big_p != false) {
  1308.     r_index =  (bytes->r_index[0] << 16)
  1309.       | (bytes->r_index[1] << 8)
  1310.     |  bytes->r_index[2];
  1311.     r_extern  = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
  1312.     r_pcrel   = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
  1313.     r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
  1314.     r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
  1315.     r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
  1316.     r_length  =       (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) 
  1317.                   >> RELOC_STD_BITS_LENGTH_SH_BIG;
  1318.   } else {
  1319.     r_index =  (bytes->r_index[2] << 16)
  1320.       | (bytes->r_index[1] << 8)
  1321.     |  bytes->r_index[0];
  1322.     r_extern  = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
  1323.     r_pcrel   = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
  1324.     r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
  1325.     r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
  1326.     r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
  1327.     r_length  =       (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) 
  1328.                   >> RELOC_STD_BITS_LENGTH_SH_LITTLE;
  1329.   }
  1330.  
  1331.   cache_ptr->howto =  howto_table_std + r_length + 4 * r_pcrel;
  1332.   /* FIXME-soon:  Roll baserel, jmptable, relative bits into howto setting */
  1333.  
  1334.   MOVE_ADDRESS(0);
  1335. }
  1336.  
  1337. /* Reloc hackery */
  1338.  
  1339. boolean
  1340. DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols),
  1341.       bfd *abfd AND
  1342.       sec_ptr asect AND
  1343.       asymbol **symbols)
  1344. {
  1345.   unsigned int count;
  1346.   bfd_size_type reloc_size;
  1347.   PTR relocs;
  1348.   arelent *reloc_cache;
  1349.   size_t each_size;
  1350.  
  1351.   if (asect->relocation) return true;
  1352.  
  1353.   if (asect->flags & SEC_CONSTRUCTOR) return true;
  1354.  
  1355.   if (asect == obj_datasec (abfd)) {
  1356.     reloc_size = exec_hdr(abfd)->a_drsize;
  1357.     goto doit;
  1358.   }
  1359.  
  1360.   if (asect == obj_textsec (abfd)) {
  1361.     reloc_size = exec_hdr(abfd)->a_trsize;
  1362.     goto doit;
  1363.   }
  1364.  
  1365.   bfd_error = invalid_operation;
  1366.   return false;
  1367.  
  1368.  doit:
  1369.   bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
  1370.   each_size = obj_reloc_entry_size (abfd);
  1371.  
  1372.   count = reloc_size / each_size;
  1373.  
  1374.  
  1375.   reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof
  1376.                                (arelent)));
  1377.   if (!reloc_cache) {
  1378. nomem:
  1379.     bfd_error = no_memory;
  1380.     return false;
  1381.   }
  1382.  
  1383.   relocs = (PTR) bfd_alloc (abfd, reloc_size);
  1384.   if (!relocs) {
  1385.     bfd_release (abfd, reloc_cache);
  1386.     goto nomem;
  1387.   }
  1388.  
  1389.   if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) {
  1390.     bfd_release (abfd, relocs);
  1391.     bfd_release (abfd, reloc_cache);
  1392.     bfd_error = system_call_error;
  1393.     return false;
  1394.   }
  1395.  
  1396.   if (each_size == RELOC_EXT_SIZE) {
  1397.     register struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
  1398.     unsigned int counter = 0;
  1399.     arelent *cache_ptr = reloc_cache;
  1400.  
  1401.     for (; counter < count; counter++, rptr++, cache_ptr++) {
  1402.       NAME(aout,swap_ext_reloc_in)(abfd, rptr, cache_ptr, symbols);
  1403.     }
  1404.   } else {
  1405.     register struct reloc_std_external *rptr = (struct reloc_std_external*) relocs;
  1406.     unsigned int counter = 0;
  1407.     arelent *cache_ptr = reloc_cache;
  1408.  
  1409.     for (; counter < count; counter++, rptr++, cache_ptr++) {
  1410.     NAME(aout,swap_std_reloc_in)(abfd, rptr, cache_ptr, symbols);
  1411.     }
  1412.  
  1413.   }
  1414.  
  1415.   bfd_release (abfd,relocs);
  1416.   asect->relocation = reloc_cache;
  1417.   asect->reloc_count = count;
  1418.   return true;
  1419. }
  1420.  
  1421.  
  1422.  
  1423. /* Write out a relocation section into an object file.  */
  1424.  
  1425. boolean
  1426. DEFUN(NAME(aout,squirt_out_relocs),(abfd, section),
  1427.       bfd *abfd AND
  1428.       asection *section)
  1429. {
  1430.   arelent **generic;
  1431.   unsigned char *native, *natptr;
  1432.   size_t each_size;
  1433.  
  1434.   unsigned int count = section->reloc_count;
  1435.   size_t natsize;
  1436.  
  1437.   if (count == 0) return true;
  1438.  
  1439.   each_size = obj_reloc_entry_size (abfd);
  1440.   natsize = each_size * count;
  1441.   native = (unsigned char *) bfd_zalloc (abfd, natsize);
  1442.   if (!native) {
  1443.     bfd_error = no_memory;
  1444.     return false;
  1445.   }
  1446.  
  1447.   generic = section->orelocation;
  1448.  
  1449.   if (each_size == RELOC_EXT_SIZE) 
  1450.     {
  1451.       for (natptr = native;
  1452.        count != 0;
  1453.        --count, natptr += each_size, ++generic)
  1454.     NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr);
  1455.     }
  1456.   else 
  1457.     {
  1458.       for (natptr = native;
  1459.        count != 0;
  1460.        --count, natptr += each_size, ++generic)
  1461.     NAME(aout,swap_std_reloc_out)(abfd, *generic, (struct reloc_std_external *)natptr);
  1462.     }
  1463.  
  1464.   if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
  1465.     bfd_release(abfd, native);
  1466.     return false;
  1467.   }
  1468.   bfd_release (abfd, native);
  1469.  
  1470.   return true;
  1471. }
  1472.  
  1473. /* This is stupid.  This function should be a boolean predicate */
  1474. unsigned int
  1475. DEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols),
  1476.       bfd *abfd AND
  1477.       sec_ptr section AND
  1478.       arelent **relptr AND
  1479.       asymbol **symbols)
  1480. {
  1481.   arelent *tblptr = section->relocation;
  1482.   unsigned int count;
  1483.  
  1484.   if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols)))
  1485.     return 0;
  1486.  
  1487.   if (section->flags & SEC_CONSTRUCTOR) {
  1488.     arelent_chain *chain = section->constructor_chain;
  1489.     for (count = 0; count < section->reloc_count; count ++) {
  1490.       *relptr ++ = &chain->relent;
  1491.       chain = chain->next;
  1492.     }
  1493.   }
  1494.   else {
  1495.     tblptr = section->relocation;
  1496.     if (!tblptr) return 0;
  1497.  
  1498.     for (count = 0; count++ < section->reloc_count;) 
  1499.       {
  1500.     *relptr++ = tblptr++;
  1501.       }
  1502.   }
  1503.   *relptr = 0;
  1504.  
  1505.   return section->reloc_count;
  1506. }
  1507.  
  1508. unsigned int
  1509. DEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect),
  1510.      bfd *abfd AND
  1511.      sec_ptr asect)
  1512. {
  1513.   if (bfd_get_format (abfd) != bfd_object) {
  1514.     bfd_error = invalid_operation;
  1515.     return 0;
  1516.   }
  1517.   if (asect->flags & SEC_CONSTRUCTOR) {
  1518.     return (sizeof (arelent *) * (asect->reloc_count+1));
  1519.   }
  1520.  
  1521.  
  1522.   if (asect == obj_datasec (abfd))
  1523.     return (sizeof (arelent *) *
  1524.             ((exec_hdr(abfd)->a_drsize / obj_reloc_entry_size (abfd))
  1525.              +1));
  1526.  
  1527.   if (asect == obj_textsec (abfd))
  1528.     return (sizeof (arelent *) *
  1529.             ((exec_hdr(abfd)->a_trsize / obj_reloc_entry_size (abfd))
  1530.              +1));
  1531.  
  1532.   bfd_error = invalid_operation;
  1533.   return 0;
  1534. }
  1535.  
  1536.  
  1537.  unsigned int
  1538. DEFUN(NAME(aout,get_symtab_upper_bound),(abfd),
  1539.      bfd *abfd)
  1540. {
  1541.   if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
  1542.  
  1543.   return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
  1544. }
  1545.  alent *
  1546. DEFUN(NAME(aout,get_lineno),(ignore_abfd, ignore_symbol),
  1547.       bfd *ignore_abfd AND
  1548.       asymbol *ignore_symbol)
  1549. {
  1550. return (alent *)NULL;
  1551. }
  1552.  
  1553.  
  1554. void 
  1555. DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how),
  1556.       bfd *ignore_abfd AND
  1557.       PTR afile AND
  1558.       asymbol *symbol AND
  1559.       bfd_print_symbol_enum_type how)
  1560. {
  1561.   FILE *file = (FILE *)afile;
  1562.  
  1563.   switch (how) {
  1564.   case bfd_print_symbol_name_enum:
  1565.     fprintf(file,"%s", symbol->name);
  1566.     break;
  1567.   case bfd_print_symbol_type_enum:
  1568.     fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),
  1569.         (unsigned)(aout_symbol(symbol)->other & 0xff),
  1570.         (unsigned)(aout_symbol(symbol)->type));
  1571.     break;
  1572.   case bfd_print_symbol_all_enum:
  1573.     {
  1574.    CONST char *section_name = symbol->section == (asection *)NULL ?
  1575.     "*abs" : symbol->section->name;
  1576.  
  1577.       bfd_print_symbol_vandf((PTR)file,symbol);
  1578.  
  1579.       fprintf(file," %-5s %04x %02x %02x %s",
  1580.           section_name,
  1581.           (unsigned)(aout_symbol(symbol)->desc & 0xffff),
  1582.           (unsigned)(aout_symbol(symbol)->other & 0xff),
  1583.           (unsigned)(aout_symbol(symbol)->type  & 0xff),
  1584.           symbol->name);
  1585.     }
  1586.     break;
  1587.   }
  1588. }
  1589.  
  1590. /* 
  1591.  provided a BFD, a section and an offset into the section, calculate
  1592.  and return the name of the source file and the line nearest to the
  1593.  wanted location.
  1594. */
  1595.  
  1596. boolean
  1597. DEFUN(NAME(aout,find_nearest_line),(abfd,
  1598.                      section,
  1599.                      symbols,
  1600.                      offset,
  1601.                      filename_ptr,
  1602.                      functionname_ptr,
  1603.                      line_ptr),
  1604.       bfd *abfd AND
  1605.       asection *section AND
  1606.       asymbol **symbols AND
  1607.       bfd_vma offset AND
  1608.       CONST char **filename_ptr AND
  1609.       CONST char **functionname_ptr AND
  1610.       unsigned int *line_ptr)
  1611. {
  1612.   /* Run down the file looking for the filename, function and linenumber */
  1613.   asymbol **p;
  1614.   static  char buffer[100];
  1615.   bfd_vma high_line_vma = ~0;
  1616.   bfd_vma low_func_vma = 0;
  1617.   asymbol *func = 0;
  1618.   *filename_ptr = abfd->filename;
  1619.   *functionname_ptr = 0;
  1620.   *line_ptr = 0;
  1621.   if (symbols != (asymbol **)NULL) {
  1622.     for (p = symbols; *p; p++) {
  1623.       aout_symbol_type  *q = (aout_symbol_type *)(*p);
  1624.       switch (q->type){
  1625.       case N_SO:
  1626.     *filename_ptr = q->symbol.name;
  1627.     if (obj_textsec(abfd) != section) {
  1628.       return true;
  1629.     }
  1630.     break;
  1631.       case N_SLINE:
  1632.  
  1633.       case N_DSLINE:
  1634.       case N_BSLINE:
  1635.     /* We'll keep this if it resolves nearer than the one we have already */
  1636.     if (q->symbol.value >= offset &&
  1637.         q->symbol.value < high_line_vma) {
  1638.       *line_ptr = q->desc;
  1639.       high_line_vma = q->symbol.value;
  1640.     }
  1641.     break;
  1642.       case N_FUN:
  1643.     {
  1644.       /* We'll keep this if it is nearer than the one we have already */
  1645.       if (q->symbol.value >= low_func_vma &&
  1646.           q->symbol.value <= offset) {
  1647.         low_func_vma = q->symbol.value;
  1648.         func = (asymbol *)q;
  1649.       }
  1650.       if (*line_ptr && func) {
  1651.         CONST char *function = func->name;
  1652.         char *p;
  1653.         strncpy(buffer, function, sizeof(buffer)-1);
  1654.         buffer[sizeof(buffer)-1] = 0;
  1655.         /* Have to remove : stuff */
  1656.         p = strchr(buffer,':');
  1657.         if (p != NULL) { *p = NULL; }
  1658.         *functionname_ptr = buffer;
  1659.         return true;
  1660.  
  1661.       }
  1662.     }
  1663.     break;
  1664.       }
  1665.     }
  1666.   }
  1667.   
  1668.   return true;
  1669.  
  1670. }
  1671.  
  1672. int 
  1673. DEFUN(NAME(aout,sizeof_headers),(ignore_abfd, execable),
  1674.       bfd *ignore_abfd AND
  1675.       boolean execable)
  1676. {
  1677.   return EXEC_BYTES_SIZE;
  1678. }
  1679.